import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { WorkorderInfoVO, WorkorderInfoForm, WorkorderInfoQuery, Accessory } from '@/api/workorder/workorderInfo/types';

/**
 * 查询工单信息列表
 * @param query
 * @returns {*}
 */

export const listWorkorderInfo = (query?: WorkorderInfoQuery): AxiosPromise<WorkorderInfoVO[]> => {
  return request({
    url: '/workorder/workorderInfo/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询工单信息详细
 * @param id
 */
export const getWorkorderInfo = (id: string | number): AxiosPromise<WorkorderInfoVO> => {
  return request({
    url: '/workorder/workorderInfo/' + id,
    method: 'get'
  });
};

/**
 * 新增工单信息
 * @param data
 */
export const addWorkorderInfo = (data: WorkorderInfoForm) => {
  return request({
    url: '/workorder/workorderInfo',
    method: 'post',
    data: data
  });
};

/**
 * 修改工单信息
 * @param data
 */
export const updateWorkorderInfo = (data: WorkorderInfoForm) => {
  return request({
    url: '/workorder/workorderInfo',
    method: 'put',
    data: data
  });
};

/**
 * 删除工单信息
 * @param id
 */
export const delWorkorderInfo = (id: string | number | Array<string | number>) => {
  return request({
    url: '/workorder/workorderInfo/' + id,
    method: 'delete'
  });
};

/**
 * 执行
 * @param id
 */
export const getStartExecute = (id: string | number | Array<string | number>) => {
  return request({
    url: '/workorder/workorderInfo/startExecute/' + id,
    method: 'get'
  });
};

/**
 * 批量添加更换备件
 *
 */
 export const addWorkorderBatch = (accessories: Accessory[]) => {
  return request({
    url: '/workorder/workorderParts/batchAdd',
    method: 'post',
    data: accessories
  });
};

/**
 * 暂存工单
 *
 */
export const tempWorkorSave = (data) => {
  return request({
    url: '/workorder/workorderInfo/tempSave',
    method: 'put',
    data: data
  });
};

/**
* 提交工单
*
*/
export const submitWorkorderSave = (data) => {
  return request({
    url: '/workorder/workorderInfo/submitSave',
    method: 'put',
    data: data
  });
};

/**
 * 确认工单
 *
 */
export const workorderConfirm = (data) => {
  return request({
    url: '/workorder/workorderInfo/workorderFinish',
    method: 'put',
    data: data
  });
};

export const getWeather = () => {
  return request({
    url: '/workorder/internetApi/queryWeather',
    method: 'get'
  });
};
